﻿using PingInfo.windows.ViewModels;
using System.Windows.Media;
using Brushes = System.Windows.Media.Brushes;

namespace PingInfo.Model
{
    public class IpEntity : BaseViewModel
    {
        private SolidColorBrush _background;
        private long _delay;
        private string _hostname;
        private string _log;

        public string Ip { get; set; }

        public long Delay
        {
            get => _delay;
            set
            {
                RaiseAndSetIfChanged(ref _delay, value, nameof(Delay));
                ChangeColorByDelay(_delay);
            }
        }

        public SolidColorBrush Background
        {
            get => _background ?? (_background = Brushes.Transparent);
            set => RaiseAndSetIfChanged(ref _background, value, nameof(Background));
        }

        public string Log
        {
            get => _log;
            set => RaiseAndSetIfChanged(ref _log, value, nameof(Log));
        }
        public string Hostname
        {
            get => _hostname;
            set => RaiseAndSetIfChanged(ref _hostname, value, nameof(Hostname));
        }

        private void ChangeColorByDelay(long a)
        {
            if (a == -1)
            {
                Background = Brushes.LightGray;
            }
            else if (a < 0)
            {
                Background = Brushes.Transparent;
            }
            else if (a <= 50)
            {
                Background = Brushes.LightGreen;
            }
            else if (a <= 100)
            {
                Background = Brushes.Gold;
            }
            else
            {
                Background = Brushes.LightSalmon;
            }

        }
    }
}
